package com.xucia.jsponic.servlet;

import java.util.Map;

import com.xucia.jsponic.data.DataObjectCloner;
import com.xucia.jsponic.data.Persistable;
import com.xucia.jsponic.remote.JsponicAction;
import com.xucia.jsponic.remote.JsponicRequest;
import com.xucia.jsponic.security.PersistentAcl;

public class GetAclObject extends JsponicAction {

	@Override
	protected Object execute(Map<String, Object> parameters,
			JsponicRequest request) throws Exception {
		Object acl = ((Persistable) parameters.get("object")).getAcl();
		if (acl instanceof PersistentAcl) {			
			acl = ((PersistentAcl)acl).getAclPersistable();
			if (Boolean.TRUE.equals(parameters.get("copy")))
				return new DataObjectCloner((Persistable)acl).clone();
			return acl;
		}
		return null;
	}

}
